package com.g2room.myuall.grap.ky;

import java.io.IOException;
import java.net.MalformedURLException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.alibaba.fastjson.JSON;
import com.g2room.driving.grap.GenericGrap;
import com.g2room.myuall.grap.ky.model.po.DicType;
import com.g2room.myuall.grap.ky.model.po.GrapErr;
import com.g2room.myuall.grap.ky.model.po.PeeArti;
import com.g2room.myuall.grap.ky.model.po.PeeUnivInfo;
import com.g2room.myuall.util.DateUtil;
import com.g2room.myuall.util.DbUtil;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;

/**
 * 根据考研大学抓取相关信息
 * @author butterfly
 *
 */
public class GrapKyUniv implements Runnable {
//	考研kaoyan.com
//	留学http://www.liuxue86.com/
//	论文http://biyelunwen.yjbys.com/
	// 抓取新闻== http://www.kaoyan.com/xinwen/
	// http://yz.kaoyan.com/ 985 211 34所
	private static final String source="考研帮";
	private static Map<String, String> infosMap = new HashMap<String, String>();
	private static Map<Integer, String> parentTtypes = new HashMap<Integer, String>();
	private static Map<String, DicType> types = getType();
	private static Map<String, Integer> areas = getArea();
	private static Map<String, Integer> univs = getUnivInfos();
	static {
		
		infosMap.put("zixun/", "院校资讯");
		infosMap.put("daoshi/", "导师介绍");
		infosMap.put("zhaosheng/", "招生信息");
		infosMap.put("fushi/", "考研复试");
		infosMap.put("tiaoji/", "考研调剂");
		infosMap.put("wenda/", "考研问答");
		infosMap.put("jingyan/", "考研经验");
		infosMap.put("ziliao/", "考研资料");
		
		infosMap.put("jianzhang/", "招生简章");
		infosMap.put("zhuanye/", "专业目录");
		infosMap.put("shumu/", "参考书目");
		infosMap.put("dagang/", "考研大纲");
		infosMap.put("chengji/", "成绩查询");
		infosMap.put("fenshuxian/", "分数线");
		infosMap.put("luqu/", "考研录取");
		infosMap.put("zhenti/", "考研真题");
		infosMap.put("baolubi/", "报录比");
		infosMap.put("tuimian/", "推荐免试");
		infosMap.put("xianchang/", "现场确认");
		infosMap.put("zaizhi/", "在职硕士");
		infosMap.put("kaochang/", "考场安排");
		infosMap.put("xuejiangzhu/", "学费奖助");
//		infosMap.put("lianxi/", "联系方式");
		infosMap.put("jieshao/", "专业介绍");
	}
	private PeeUnivInfo pui;
	/** 省份URL */
	private String url;
	public String prov;
	public GrapKyUniv(String url, String prov) {
		this.url = url;
		this.prov = prov;
	}
	public GrapKyUniv() {
	}
	public static void main(String[] args) throws Exception{
//		Map<String, String> provMap = getProvince();
//		System.out.println("抓取数量：" + provMap.size());
//		for(String url : provMap.keySet()) {
//			GrapKyUniv gku = new GrapKyUniv(url, provMap.get(url));
//			Thread thread = new Thread(gku);
//			thread.start();
//		}
		
//		GrapKyUniv gku = new GrapKyUniv("http://www.kaoyan.com/beijing/", "北京");
//		gku.getUnivs();
		
		GrapKyUniv gku = new GrapKyUniv();
		List<GrapErr> ges = gku.getErrDb();
		for(GrapErr ge : ges) {
			try {
				if(ge.getType().equals("2")) {
					gku.prov =  ge.getDescription();
					gku.getUniv(ge.getUrl(), ge.getContent());
	//			} else if(ge.getType().equals("3")) {
	//				gku.prov =  ge.getDescription();
				} else if(ge.getType().equals("4")) {
					// http://yz.kaoyan.com/dlut/wenda/
					gku.getInfos(ge.getUrl());
				} else if(ge.getType().equals("5")) {
					gku.getListData(ge.getUrl(), ge.getDescription());
				} else if(ge.getType().equals("6")) {
					gku.pui = JSON.parseObject(ge.getContent(), PeeUnivInfo.class);
					gku.getDetailData(ge.getUrl(), ge.getDescription());
				} else if(ge.getType().equals("9")) {
					GrapKyUniv.insert2ArtiDb(JSON.parseObject(ge.getContent(), PeeArti.class));
				} else {
					continue;
				}
				gku.delFromErrDb(ge.getId());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	private static Map<String, String> getProvince() {
		String str = "<ul class='sblist'><li><a href='http://www.kaoyan.com/beijing/' title='北京' target='_blank'>北京</a></li><li><a href='http://www.kaoyan.com/jiangsu/' title='江苏' target='_blank'>江苏</a></li><li><a href='http://www.kaoyan.com/shanghai/' title='上海' target='_blank'>上海</a></li><li><a href='http://www.kaoyan.com/guangdong/' title='广东' target='_blank'>广东</a></li><li><a href='http://www.kaoyan.com/shaanxi/' title='陕西' target='_blank'>陕西</a></li><li><a href='http://www.kaoyan.com/hubei/' title='湖北' target='_blank'>湖北</a></li><li><a href='http://www.kaoyan.com/shandong/' title='山东' target='_blank'>山东</a></li><li><a href='http://www.kaoyan.com/liaoning/' title='辽宁' target='_blank'>辽宁</a></li><li><a href='http://www.kaoyan.com/hebei/' title='河北' target='_blank'>河北</a></li><li><a href='http://www.kaoyan.com/sichuan/' title='四川' target='_blank'>四川</a></li><li><a href='http://www.kaoyan.com/tianjin/' title='天津' target='_blank'>天津</a></li><li><a href='http://www.kaoyan.com/zhejiang/' title='浙江' target='_blank'>浙江</a></li><li><a href='http://www.kaoyan.com/hunan/' title='湖南' target='_blank'>湖南</a></li><li><a href='http://www.kaoyan.com/chongqing/' title='重庆' target='_blank'>重庆</a></li><li><a href='http://www.kaoyan.com/anhui/' title='安徽' target='_blank'>安徽</a></li><li><a href='http://www.kaoyan.com/henan/' title='河南' target='_blank'>河南</a></li><li><a href='http://www.kaoyan.com/jilin/' title='吉林' target='_blank'>吉林</a></li><li><a href='http://www.kaoyan.com/fujian/' title='福建' target='_blank'>福建</a></li><li><a href='http://www.kaoyan.com/yunnan/' title='云南' target='_blank'>云南</a></li><li><a href='http://www.kaoyan.com/shanxi/' title='山西' target='_blank'>山西</a></li><li><a href='http://www.kaoyan.com/jiangxi/' title='江西' target='_blank'>江西</a></li><li><a href='http://www.kaoyan.com/gansu/' title='甘肃' target='_blank'>甘肃</a></li><li><a href='http://www.kaoyan.com/guangxi/' title='广西' target='_blank'>广西</a></li><li><a href='http://www.kaoyan.com/guizhou/' title='贵州' target='_blank'>贵州</a></li><li><a href='http://www.kaoyan.com/xinjiang/' title='新疆' target='_blank'>新疆</a></li><li><a href='http://www.kaoyan.com/hainan/' title='海南' target='_blank'>海南</a></li><li><a href='http://www.kaoyan.com/qinghai/' title='青海' target='_blank'>青海</a></li><li><a href='http://www.kaoyan.com/ningxia/' title='宁夏' target='_blank'>宁夏</a></li><li><a href='http://www.kaoyan.com/xizang/' title='西藏' target='_blank'>西藏</a></li><li><a href='http://www.kaoyan.com/heilongjiang/' title='黑龙江' target='_blank'>黑龙江</a></li><li><a href='http://www.kaoyan.com/neimenggu/' title='内蒙古' target='_blank'>内蒙古</a></li><li><a href='http://www.kaoyan.com/pages/211/' title='211' target='_blank'>211</a></li><li><a href='http://www.kaoyan.com/pages/985/' title='985' target='_blank'>985</a></li><li><a href='http://www.kaoyan.com/pages/34/' title='34' target='_blank'>34所</a></li></ul>";

		Document doc = null;
		try {
			doc = GenericGrap.getDocByHtml(str);
		} catch (Exception e) {
			e.printStackTrace();
		}
		Map<String, String> provMap = new HashMap<String, String>();
		if(doc == null) return provMap;
		Elements aEls = doc.getElementsByTag("a");
		for(Element ael : aEls) {
			String prov = ael.text();
			if(prov.contains("211") || prov.contains("985") || prov.contains("34")) continue;
			provMap.put(ael.attr("href"), ael.text());
		}
		return provMap;
	}
	
	/**
	 * 获取分页列表
	 * @param url
	 * @throws FailingHttpStatusCodeException
	 * @throws MalformedURLException
	 * @throws IOException
	 */
	public void getUnivs() {
		Document doc = null;
		try {
			doc = GenericGrap.getDocByIp(url);
			if(doc == null) return;
	//		doc.getElementsByAttributeValueContaining(key, match)
			Elements dlEls = doc.getElementsByAttributeValueContaining("class", "schoolListItem");
			Map<String, String> univUrls = new HashMap<String, String>();
			for(Element dlEl : dlEls) {
				Elements dtEls = dlEl.getElementsByTag("dt");
				for(Element dtEl : dtEls) {
					univUrls.put(dtEl.getElementsByTag("a").attr("href"), dtEl.text());
				}
			}

			System.out.println(prov+ "大学数量：" + univUrls.size());
	        for(String univUrl : univUrls.keySet()) {
	        	getUniv(univUrl, univUrls.get(univUrl));
	        }
		} catch (Exception e) {
			System.out.println(url);
			e.printStackTrace();
			GrapErr ge = new  GrapErr();
			ge.setUrl(url);
			ge.setType("1");
			ge.setContent(prov);
			ge.setDescription("获取Univ  Page错误："+e.getMessage());
			insert2ErrDb(ge);
		}
	}

	/**
	 * 获取List列表
	 * @param url
	 */
	public void getUniv(String url, String univ) {
		// 获取分页信息
		Document doc = null;
		try {
			doc = GenericGrap.getDocByIp(url);
			if(doc == null) return;
			pui = new PeeUnivInfo();
			pui.setName(univ);
			pui.setSource(source);
			pui.setSourceUrl(url);
			pui.setProvinceName(prov);
			pui.setProvinceId(areas.get(prov));
			
			pui.setCode(url.replace("http://yz.kaoyan.com/", "").replace("/", ""));
			Elements divEls = doc.getElementsByAttributeValue("class", "schoolArea");
			if(null != divEls && divEls.size() > 0) {
				Elements pEls = divEls.first().getElementsByTag("p");
				if(null != pEls && pEls.size() > 0) {
					Element pEl = pEls.get(0);
					Elements aels = pEl.getElementsByTag("a");
					if(null != aels && aels.size() > 0) {
						pui.setDescription(getContact(aels.first().attr("href")));
					}
					Elements strongels = pEl.getElementsByTag("strong");
					if(null != strongels && strongels.size() > 0) {
						pui.setSchoolName(strongels.first().text());
						pui.setSchoolId(univs.get(pui.getSchoolName()));
					}
					
					pEl = pEls.get(1);
					if(pEl.outerHtml().contains("mt5")){
						if(null != pEl.getElementsByTag("a") && !pEl.getElementsByTag("a").isEmpty()) {
						pui.setUnivUrl(pEl.getElementsByTag("a").first().attr("href"));
						pui.setUnivUrlTitle(pEl.getElementsByTag("a").first().text());
						}
					}
					pEl = pEls.get(2);
					pui.setAddress(pEl.text());
	
					pEl = pEls.get(3);
					pui.setZipCode(pEl.text());
	
					pEl = pEls.get(4);
					pui.setPhone(pEl.text());
					
					// 获取联系方式（北京大学研招办联系方式）
					pEl = pEls.get(5);
					if(null != pEl) {
						Elements aEls = pEl.getElementsByTag("a");
						if(null != aEls && !aEls.isEmpty()) {
							pui.setContact(getContact(aEls.first().attr("href")));
						}
					}
					pui.setBanner("http://img.kaoyan.com/school/banner/timg_"+pui.getCode()+".jpg");
					pui.setLogo("http://img.kaoyan.com/school/logo/"+pui.getCode()+"_logo.png");
				}
			}
			insert2UnivDb(pui);
	        getInfos(url);
		} catch (Exception e) {
			System.out.println(url);
			e.printStackTrace();
			GrapErr ge = new  GrapErr();
			ge.setUrl(url);
			ge.setType("2");
			ge.setContent(e.getMessage());
			ge.setDescription("获取List错误");
			insert2ErrDb(ge);
		}
	}
	
	private String getContact(String url) {
		Document doc = null;
		try {
			doc = GenericGrap.getDocByIp(url);
		} catch (Exception e) {
			System.out.println(url);
			e.printStackTrace();
			GrapErr ge = new  GrapErr();
			ge.setUrl(url);
			ge.setType("3");
			ge.setContent(e.getMessage());
			ge.setDescription("获取List错误");
			insert2ErrDb(ge);
		}
		Elements divEls = doc.getElementsByAttributeValue("class", "articleCon");
		return null != divEls && divEls.size() > 0 ? divEls.first().html() : "";
	}
	
	/**
	 * 获取大学资讯、招生简章、师资力量等
	 */
	public void getInfos(String univUrl) {
		for(String urlSub : infosMap.keySet()) {
			String url = univUrl + urlSub;
			Document doc = null;
			try {
				doc = GenericGrap.getDocByIp(url);
			
				if(doc == null) continue;
				// 获取分页数据
				List<String> pages = new ArrayList<String>();
				pages.add(url);
				Elements pageEls = doc.getElementsByAttributeValue("class", "tPage");
				if(null != pageEls && !pageEls.isEmpty()) {
					// 有分页，获取倒数第二个a标签
					Elements aEls = pageEls.first().getElementsByTag("a");
					if(aEls.size() > 1) {
						Integer pageNum = Integer.valueOf(aEls.get(aEls.size() - 2).text());
						for(int i = 2; i<= pageNum; i ++) {
							// http://yz.kaoyan.com/pku/tuimian/index_2.html
							pages.add(url + "index_"+i+".html");
						}
					}
				}
				
				for(String pageUrl : pages) {
					getListData(pageUrl, infosMap.get(urlSub));
				}
				
			} catch (Exception e) {
				e.printStackTrace();
				GrapErr ge = new  GrapErr();
				ge.setUrl(url);
				ge.setType("4");
				ge.setContent(e.getMessage());
				ge.setDescription("获取Page错误:" + infosMap.get(urlSub));
				System.out.println(url);
				insert2ErrDb(ge);
			}
		}
	}
	/**
	 * 获取列表数据
	 * @param url
	 * @param type	列表数据类型
	 * @return
	 */
	public void getListData(String url, String type) {
		Document doc = null;
		try {
			doc = GenericGrap.getDocByIp(url);
			if(doc == null) return;
			Elements ulEls = doc.getElementsByAttributeValue("class", "subList");
			if(null != ulEls && !ulEls.isEmpty()) {
				Elements aEls = ulEls.first().getElementsByTag("a");
				List<String> detailUrls = new ArrayList<String>();
				for(Element aEl : aEls) {
					detailUrls.add(aEl.attr("href"));
				}
				
				for(String detailUrl : detailUrls) {
					getDetailData(detailUrl, type);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			GrapErr ge = new  GrapErr();
			ge.setUrl(url);
			ge.setType("5");
			ge.setContent(e.getMessage());
			ge.setDescription(type);
			insert2ErrDb(ge);
		}
	}

	/**
	 * 获取详情数据
	 * @param url
	 * @param type	数据类型
	 * @return
	 */
	public void getDetailData(String url, String type) {
		if(url.contains("download") || null == pui) return;
		type = type.replace("=Read timed out", "").replace("=connect timed out", "").replace("=null=null", "");
		Document doc = null;
		try {
			doc = GenericGrap.getDocByIp(url);
			if(doc == null) return;
			PeeArti pa = new PeeArti();
			DicType dt = types.get(type);
			pa.setTypeName(dt.getName());
			pa.setTypeId(dt.getId());
			pa.setCategoryId(dt.getParentId());
			pa.setCategoryName(parentTtypes.get(dt.getParentId()));
		
			pa.setSchoolCode(pui.getCode());
			pa.setSchoolId(pui.getSchoolId());
			pa.setSchoolName(pui.getSchoolName());
			pa.setProvinceId(pui.getProvinceId());
			pa.setProvinceName(pui.getProvinceName());
			pa.setSource(source);
			pa.setSourceUrl(url);
			
			Elements els = doc.getElementsByAttributeValue("class", "articleTitle");
			if(null != els && !els.isEmpty()) {
				pa.setTitle(els.text());
			} else {
				return;
			}
			els = doc.getElementsByAttributeValue("class", "articleCon");
			if(null != els && !els.isEmpty()) {
				pa.setContent(els.first().html());
			} else {
				return;
			}
			els = doc.getElementsByAttributeValue("class", "articleInfo");
			if(null != els && !els.isEmpty()) {
				Elements spanEls = els.first().getElementsByTag("span");
				if(spanEls.size() > 0) {
					// 2004-09-08 16:22
					String publishTime = spanEls.get(0).text();
					try {
						pa.setPublishTime(DateUtil.string2Date(publishTime, "yyyy-MM-dd HH:mm"));
					} catch (ParseException e) {
						e.printStackTrace();
					}
				} else {
					return;
				}
			} else {
				return;
			}
			try {
				insert2ArtiDb(pa);
			} catch (Exception e) {
				e.printStackTrace();
				GrapErr ge = new  GrapErr();
				ge.setUrl(url);
				ge.setType("9");
				ge.setContent(JSON.toJSONString(pa));
				ge.setDescription(e.getMessage());
				insert2ErrDb(ge);
			}
		} catch (Exception e) {
			System.out.println(url);
			e.printStackTrace();
			GrapErr ge = new  GrapErr();
			ge.setUrl(url);
			ge.setType("6");
			ge.setContent(JSON.toJSONString(pui));
			ge.setDescription(type + "=" + e.getMessage());
			insert2ErrDb(ge);
		}
	}
	

	public static void insert2ArtiDb(PeeArti pg) throws Exception {
		String sql = "insert into pee_univ_arti(type_name,content,source_url,school_code,source,title,province_name,school_name,publish_time,province_id,school_id,type_id,category_name,category_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement ps = null;
		try {
			ps = DbUtil.getConn().prepareStatement(sql);
			// type_name,content,source_url,school_code,source,title,province_name,school_name,publish_time,province_id,school_id,type_id,category_name,category_id
			ps.setString(1, pg.getTypeName());
			ps.setString(2, pg.getContent());
			ps.setString(3, pg.getSourceUrl());
			ps.setString(4, pg.getSchoolCode());
			ps.setString(5, pg.getSource());
			ps.setString(6, pg.getTitle());
			ps.setString(7, pg.getProvinceName());
			ps.setString(8, pg.getSchoolName());
			ps.setDate(9, new java.sql.Date(pg.getPublishTime().getTime()));
			ps.setInt(10, pg.getProvinceId());
			ps.setInt(11, null == pg.getSchoolId()?0:pg.getSchoolId());
			ps.setInt(12, pg.getTypeId());
			ps.setString(13, pg.getCategoryName());
			ps.setInt(14, pg.getCategoryId());
			
			ps.execute();	
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			if(null != ps) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	public static void insert2UnivDb(PeeUnivInfo pui) throws Exception {
		PreparedStatement ps = null;
		try {
			String sql = "insert into pee_univ_info(contact,province_name,description,univ_url,univ_url_title,source_url,address,name,source,phone,summary,zip_code,code,school_name,logo,banner,province_id,school_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			ps = DbUtil.getConn().prepareStatement(sql);
			//contact,province_name,description,univ_url,univ_url_title,source_url,
			//address,name,source,phone,summary,zip_code,code,province_id,school_id
			ps.setString(1, pui.getContact());
			ps.setString(2, pui.getProvinceName());
			ps.setString(3, pui.getDescription());
			ps.setString(4, pui.getUnivUrl());
			ps.setString(5, pui.getUnivUrlTitle());
			ps.setString(6, pui.getSourceUrl());
			
			ps.setString(7, pui.getAddress());
			ps.setString(8, pui.getName());
			ps.setString(9, pui.getSource());
			ps.setString(10, pui.getPhone());
			ps.setString(11, pui.getSummary());
			ps.setString(12, pui.getZipCode());
			ps.setString(13, pui.getCode());
			ps.setString(14, pui.getSchoolName());
			ps.setString(15, pui.getLogo());
			ps.setString(16, pui.getBanner());
			ps.setInt(17, pui.getProvinceId());
			ps.setInt(18, null == pui.getSchoolId()?0:pui.getSchoolId());
			ps.execute();
			
		} catch(Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			if(null != ps) {
				try {
					ps.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	public void insert2ErrDb(GrapErr ge) {
		PreparedStatement grapPs = null;
		try {
			grapPs = DbUtil.getConn().prepareStatement("insert into grap_err(description,url,content,type) values(?,?,?,?)");
			grapPs.setString(1, ge.getDescription());
			grapPs.setString(2, ge.getUrl());
			grapPs.setString(3, ge.getContent());
			grapPs.setString(4, ge.getType());
			grapPs.execute();
			grapPs.close();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			if(null != grapPs) {
				try {
					grapPs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	

	
	public void delFromErrDb(int id) {
		PreparedStatement grapPs = null;
		try {
			grapPs = DbUtil.getConn().prepareStatement("delete from  grap_err where id=?");
			grapPs.setInt(1, id);
			grapPs.execute();
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			if(null != grapPs) {
				try {
					grapPs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
	

	public List<GrapErr> getErrDb() {
		List<GrapErr> univs = new ArrayList<GrapErr>();
		try {
			Connection connection = DbUtil.getConn();
			Statement statement = connection.createStatement();
			String sql = "select * from grap_err";
			ResultSet rs = statement.executeQuery(sql);
			while(rs.next()) {
				GrapErr univ = new GrapErr();
				univ.setId(rs.getInt("id"));
				univ.setUrl(rs.getString("url"));
				univ.setType(rs.getString("type"));
				univ.setContent(rs.getString("content"));
				univ.setDescription(rs.getString("description"));
				univs.add(univ);
			}
			rs.close();
			statement.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return univs;
	}
	
	@Override
	public void run() {
		getUnivs();
	}
	

	public static Map<String, DicType> getType() {
		Map<String, DicType> univs = new HashMap<String, DicType>();
		try {
			Connection connection = DbUtil.getConn();
			Statement statement = connection.createStatement();
			String sql = "select * from dic_type where type=2";
			ResultSet rs = statement.executeQuery(sql);
			parentTtypes =  new HashMap<Integer, String>();
			while(rs.next()) {
				DicType dt = new DicType();
				dt.setId(rs.getInt("id"));
				dt.setName(rs.getString("name"));
				dt.setParentId(rs.getInt("parent_id"));
				
				univs.put(dt.getName(), dt);
				parentTtypes.put(dt.getId(), dt.getName());
			}
			rs.close();
			statement.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return univs;
	}
	

	public static Map<String, Integer> getArea() {
		Map<String, Integer> univs = new HashMap<String, Integer>();
		try {
			Connection connection = DbUtil.getConn();
			Statement statement = connection.createStatement();
			String sql = "select id,name from sys_area where pid = 0";
			ResultSet rs = statement.executeQuery(sql);
			while(rs.next()) {
				univs.put(rs.getString("name"), rs.getInt("id"));
			}
			rs.close();
			statement.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return univs;
	}
	public static Map<String, Integer> getUnivInfos() {
		Map<String, Integer> univs = new HashMap<String, Integer>();
		try {
			Connection connection = DbUtil.getConn();
			Statement statement = connection.createStatement();
			String sql = "select id,name from univ_info";
			ResultSet rs = statement.executeQuery(sql);
			while(rs.next()) {
				univs.put(rs.getString("name"), rs.getInt("id"));
			}
			rs.close();
			statement.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return univs;
	}
}
